/**
 * 二八杠游戏界面
 * @author none
 */
//游戏状态
enum TEBGameStatus {
    GS_WK_NULL = -1,//其他状态
    GS_WK_READY = 101,//准备状态
    GS_WK_CALL_BANKER = 102,//抢庄状态
    GS_WK_SET_BANKER = 103,//庄家宣布状态
    GS_WK_CALL_BET = 104,//投注状态
    GS_WK_SHAKE_DICE = 105,//骰子状态
    GS_WK_OPEN_CARD = 106,//开奖状态
    GS_WK_GAME_OVER = 200,//游戏结束
}

// class TEBGameSceneModule extends base.BaseGameSceneModule {
//     public static response: any = {
//         onResize: how.Application.APPEVENT_RESIZE,//重新定位筹码
//         appHide: how.Application.APPEVENT_PAUSE,
//         appResume: how.Application.APPEVENT_RESUME,
//         onReady: TEBCMDConfig.TEB_GET_ON_READY,//开始准备
//         startBanker: TEBCMDConfig.TEB_GET_ON_BANKER,//开始叫庄
//         getGrabBanker: TEBCMDConfig.TEB_GET_GRAB_BANKER,//用户抢庄信息
//         setBanker: TEBCMDConfig.TEB_GET_BANKER,//庄家宣布
//         getOnScore: TEBCMDConfig.TEB_GET_ON_SCORE,//开始下注
//         getScore: TEBCMDConfig.TEB_GET_SCORE,//玩家加注信息
//         getDice: TEBCMDConfig.TEB_GET_DICE_RESULT,//摇骰子结果
//         openCard: TEBCMDConfig.TEB_GET_OPEN_CARD,//开牌结果
//         playerExit: TEBCMDConfig.TEB_GET_PLAYER_EXIT,//用户退出
//         gameEnd: TEBCMDConfig.TEB_GET_GAME_END,//用户退出
//         displayBanker: "displayBanker",//设置庄家
//         resultRemove: "resultRemove",//结果界面删除
//         sitError: CMDConfig.GET_SIT_ERROR,//坐下失败
//         onSystemTalk: CMDConfig.GET_SYSMESSAGE,//通知退出房间失败
//     }
//     public static request: any = {
//         enteredPlayer: "enteredPlayer",//以坐下的玩家信息
//         introduction: "introduction",//介绍
//         setting: "setting",//设置
//         record: "record",//记录
//         noGrab: "noGrab",//不抢
//         grab: "grab",//抢庄
//         continue: "continue",//继续游戏
//         onCancelButton: "onCancelButton",//取消匹配
//         onBackButton: "onBackButton",//退出游戏
//         chipLeave: "chipLeave",//筹码以移除，出现删除页面
//         playerCard: "playerCard",//玩家牌到位
//         setOpenCardFlag: "setOpenCardFlag",//可以开牌
//         callScore: "callScore",//下注
//         setFirstAnimation: "setFirstAnimation",//设置第一个发牌的人
//     }
//     private chairId: number = -1;//我方玩家椅子号
//     private resultFlag: boolean = false;//是否打开了结束界面
//     private resultTimeout: number = -1;//计时器
//     //随机庄加走马灯
//     private bankerInterval: number = -1;
//     private totalTime: number = 0;
//     private runningTime: number = 0;
//     private bankerList: Array<number> = [];//走马灯玩家
//     private bankerLenght: number = 0;
//     //庄家椅子号
//     private bankerChair: number = -1;
//     public quxiaopipeiSuccess = false;//是否取消匹配成功
//     //游戏状态
//     private state: TEBGameStatus;
//     private clickedFlag: boolean = false;//是否抢庄或者下注
//     public clickQuitFlag: boolean = false;//是否退出游戏中
//     private noShowEver: boolean = true;//重新返回界面时候，如果游戏已经结束，而且显示过结束页面
//     public onGUIComplete(event: egret.Event): void {
//         how.SoundManager.stopMusic();
//         how.ComponentUtils.init(false, "TEBAlertSkin", "TEBDialogSkin", "public.BannerSkin", "TEBHallSceneNoticeSkin",
//             "public.LoaddingSkin", "TEBGameSceneNoticeSkin", "TEBSettingWindowSkin");//初始化通用组件
//         //除去loading页
//         this.communicate(LoaddingGlobalModule.response.hideLoad);
//         this.initParam();
//         super.onGUIComplete(event);
//     }

//     public initParam() {
//         // // if (AppData.getInstance().lastGameId == 0) {
//         if (D.App.userData.userStatus != UserStatus.PLAY) {
//             //坐下
//             let pd = base.Utils.getItem(AppData.getInstance().gameData.playerList, "id", AppData.getInstance().userData.id);
//             if(pd){
//                 AppData.getInstance().gameData.playerList = [];
//                 AppData.getInstance().gameData.playerList.push(pd);
//             } 
//             this.state = TEBGameStatus.GS_WK_NULL;
//             this.isBackstatus = BackStatusConfig.pipei;
//             this.hallSocket.send(CMDConfig.SEND_SIT, {
//                 wTableID: 0,
//                 wChairID: 65535,
//                 szTablePass: AppData.getInstance().currentRoom.szTablePass,
//                 cbPassLen: AppData.getInstance().currentRoom.cbPassLen,
//                 CellScore: AppData.getInstance().currentRoom.cellScore,
//                 PreScore: AppData.getInstance().currentRoom.preScore
//             });
//         } else {
//             //同步牌桌信息
//             this.hallSocket.send(CMDConfig.SEND_SYNTABLE, { bAllowLookon: 1 });
//             AppData.getInstance().lastGameId = 0;//恢复游戏
//             AppData.getInstance().lastServerId = 0;
//         }
//         for (var i = 0; i < 4; i++) {
//             this["player" + i] = this.moduleManager.initModule(TEBPlayerModule, this.gui["player" + i], TEBPlayerData);
//             // this["player" + i].setType(i % 2);
//         }
//     }
//     /**************************************服务端消息******************************************** */
//     public enteredPlayer(data: base.PlayerData): void {//更新坐下玩家 
//         if (this.chairId == -1) return;
//         var player = this["player" + data.seatID];
//         if (player && (!player.data || (player.data && player.data.id != data.id))) {
//             player.data = data;
//         }
//     }
//     //玩家状态信息
//     public onMyStatusChange(data: any): void {
//         switch (data.S) {
//             case UserStatus.NULL:   //当玩家离开
//                 if (this.isBackstatus == BackStatusConfig.back || this.isBackstatus == BackStatusConfig.gameStart) {//如果面板状态是返回
//                     // AppData.getInstance().lastPreScore = AppData.getInstance().currentRoom.id > 7204 ? 1 : 0;
//                     this.communicate(base.ChangeServerGlobalModule.response.changeServer, null, true, () => {
//                         this.moduleManager.initModule(MainSceneModule, MainSceneView);
//                     });
//                 }
//                 break;
//             case UserStatus.SIT:  //当玩家坐下
//                 if (this.isBackstatus == BackStatusConfig.pipei) {
//                     this.chairId = AppData.getInstance().userData.chairID;
//                     this.callData("checkPlayerList");//玩家确定桌子号之后，查找同桌子ID的玩家
//                     this.isBackstatus = BackStatusConfig.gameStart;
//                 }
//                 break;
//             case UserStatus.PIPEI:  //匹配
//                 this.callUI("showPiPeiUI", false);
//                 //AppData.getInstance().userData.tableID = data.wTableID;
//                 AppData.getInstance().userData.chairID = data.C;
//                 AppData.getInstance().userData.status = data.S;
//                 break;
//             case UserStatus.READY:  //准备
//             case UserStatus.PLAY:  //比赛开始
//                 this.callData("setBaseScore", AppData.getInstance().currentRoom.cellScore);
//                 this.callUI("hidePiPeiUI");
//                 this.callData("setRound", 1);
//                 this.callUI("setRound", 1);
//                 this.isBackstatus = BackStatusConfig.gameStart;
//                 AppData.getInstance().gameData.gameStart = true;
//                 break;
//             case UserStatus.FREE://当玩家起立:取消匹配，继续游戏
//                 AppData.getInstance().userData.status = UserStatus.FREE;
//                 if (this.isBackstatus == BackStatusConfig.quXiaoPiPei && !this.quxiaopipeiSuccess) {
//                     this.quxiaopipeiSuccess = true;
//                     this.callUI("hidePiPeiUI");
//                     this.callUI("setContinueGroup", true);
//                 } else if (this.isBackstatus == BackStatusConfig.resumeGame) {
//                     this.isBackstatus = BackStatusConfig.pipei;
//                     this.hallSocket.send(CMDConfig.SEND_SIT, {
//                         wTableID: 0,
//                         wChairID: 65535,
//                         szTablePass: AppData.getInstance().currentRoom.szTablePass,
//                         cbPassLen: AppData.getInstance().currentRoom.cbPassLen,
//                         CellScore: AppData.getInstance().currentRoom.cellScore,
//                         PreScore: AppData.getInstance().currentRoom.preScore
//                     });
//                 }
//                 break;
//         }
//     }
//     //开始一轮游戏
//     // {"dwGameStartTime":1497346404,"lCellScore":100,"cbRetsOfRound":1,"cbOpenCardData":[0,0,0,0,0,0,0,0,0,0]}
//     public onReady(data: any) {
//         this.noShowEver = false;
//         this.state = TEBGameStatus.GS_WK_READY;
//         if (data.dwGameStartTime != 0) {
//             this.callUI("showGameId", data.dwGameStartTime);
//         }
//         this.callUI("setGameStart", data);
//         this.callData("setRound", data.cbRetsOfRound);
//         for (var i = 0; i < 4; i++) {
//             this["player" + i].restart();
//         }
//         this.callUI("removeAllAnimation");
//         if (data.cbRetsOfRound > 1) {
//             //下一局开始，开始倒计时，然后播放动画
//             if (this.resultTimeout != -1) {
//                 egret.clearTimeout(this.resultTimeout);
//                 this.resultTimeout = -1;
//             }
//             //断线重连，如果没有打开界面的话，打开界面
//             if (!this.resultFlag) {
//                 this.moduleManager.initModule(TEBResultWindowModule, TEBResultWindowView, TEBResultWindowData);
//                 this.resultFlag = true;
//                 var resultList: Array<TEBResultData> = this.callData("getResultData");
//                 //获取不到数据
//                 if (resultList.length == 0) {
//                     var data = this.callData("getGameResult");//获取开牌信息
//                     if (data == null) return;
//                     var list = data.cbPrizeCount, cellScore = AppData.getInstance().currentRoom.cellScore;
//                     //计算庄家倍数
//                     var wAddScoreTimes = data.wAddScoreTimes, bankerTime = 0;
//                     for (var t = 0; t < 4; t++) {
//                         if (list[t] > 0) {
//                             bankerTime -= wAddScoreTimes[t];
//                         } else {
//                             bankerTime += wAddScoreTimes[t];
//                         }
//                     }
//                     wAddScoreTimes[data.wBankerUser] = Math.abs(bankerTime);
//                     for (var i = 0; i < 4; i++) {
//                         var item: TEBResultData = new TEBResultData();
//                         item.nickname = this[this.getPlayerByChair(i)].data.nickName;
//                         item.base = cellScore;
//                         item.score = list[i];
//                         item.times = wAddScoreTimes[i];
//                         resultList.push(item);
//                     }
//                 }
//                 if (resultList.length >= 0) {
//                     this.communicate(TEBResultWindowModule.response.setInfo, resultList, this.chairId, this.callData("getBanker"),
//                         this.callData("getLastGame"), this.callData("getRound"));
//                 }
//             }
//             this.communicate(TEBResultWindowModule.response.readyNextGame, data.cbRetsOfRound);
//         }
//     }

//     //开始叫庄
//     // {"wGameType":1,"cbBankerTimes":[1,2,3,4]}
//     public startBanker(data: any) {
//         this.clickedFlag = false;
//         this.state = TEBGameStatus.GS_WK_CALL_BANKER;
//         this.callData("setGameType", data.wGameType);
//         this.callUI("startBanker", data);
//         //关闭结果页面
//         if (this.resultFlag) {
//             this.communicate(TEBResultWindowModule.response.closeResult);
//             this.resultFlag = false;
//         }
//         for (var i = 0; i < 4; i++) {
//             if (i != this.chairId) {
//                 this[this.getPlayerByChair(i)].setThinking();
//             }
//         }
//     }

//     //用户抢庄返回
//     // {"wGameType":1,"wChairID":2,"wCallTimes":5}
//     public getGrabBanker(data: any) {
//         var value = data.wCallTimes == 0 ? false : true;
//         this[this.getPlayerByChair(data.wChairID)].setGrabBanker(data.wGameType, data.wCallTimes);
//         if (value) {
//             this.callData("updataBanker", data.wChairID);
//         }
//         if (data.wChairID == this.chairId) {
//             this.callUI("closeGrabGroup");
//         }
//         this[this.getPlayerByChair(data.wChairID)].closeThinking();
//     }
//     //设置庄家
//     // {"wGameType":1,"wChairID":2,"wCallTimes":5}
//     public setBanker(data: any) {
//         this.state = TEBGameStatus.GS_WK_SET_BANKER;
//         this.callUI("closeGrabGroup");
//         this.callUI("setBankerFlag", this.chairId == data.wChairID);
//         this.callData("setBanker", data.wChairID);
//         this.bankerList = this.callData("getBankerList");
//         this.bankerLenght = this.bankerList.length;
//         this.bankerChair = data.wChairID;
//         this.runningTime = 0;
//         if (this.bankerLenght == 1) {//只有一人叫庄            
//             this[this.getPlayerByChair(data.wChairID)].setBankerAnimation();
//         } else {
//             if (this.bankerLenght == 0) {//无人叫庄
//                 this.bankerList = [0, 1, 2, 3];
//                 this.bankerLenght = 4;
//             }
//             if (AppData.getInstance().isGameHide) {
//                 this.setBankerByIndex(this.bankerChair);
//             } else {
//                 this.startRandomBanker();
//             }
//         }
//         for (var i = 0; i < 4; i++) {
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//     }
//     //开始下注
//     // {"wGameType":1,"wMaxTime":100}
//     public getOnScore(data: any) {
//         this.clickedFlag = false;
//         this.state = TEBGameStatus.GS_WK_CALL_BET;
//         if (this.chairId != this.callData("getBanker")) {//庄家不需要投注
//             if (data.wGameType == 1) {//普通房直接返回
//                 this.callScore(1);
//             } else {
//                 this.callUI("startCallScore", data);
//             }
//         } else {
//             this.callUI("startCallScore1");
//         }
//         for (var i = 0; i < 4; i++) {
//             if (i != this.bankerChair && i != this.chairId) {
//                 this[this.getPlayerByChair(i)].setThinking();
//             }
//         }
//     }
//     //玩家下注信息
//     // {"wGameType":2,"wAddScoreUser":1,"lAddScoreCount":100,lplayerScore:1000}
//     public getScore(data: any) {
//         this.state = TEBGameStatus.GS_WK_CALL_BET;
//         var chair = this.getNoByChair(data.wAddScoreUser), list = this.callData("getChipList", data.lAddScoreCount);
//         if (AppData.getInstance().isGameHide) {
//             this.callUI("chipActionByData", list, data.lAddScoreCount);
//         } else {
//             this.callUI("chipAction", chair, list, data.lAddScoreCount);
//         }
//         //计算倍数
//         data.lAddScoreTimes = data.lAddScoreCount / AppData.getInstance().currentRoom.cellScore;
//         this[this.getPlayerByChair(data.wAddScoreUser)].setBetScore(data);
//         this[this.getPlayerByChair(data.wAddScoreUser)].closeThinking();
//         if (this.chairId == data.wAddScoreUser) {
//             this.callUI("closeCallScore");
//             this.callUI("updateMyBetScore", data.lAddScoreCount);
//         }
//     }
//     //摇骰子结果
//     public getDice(data: any) {
//         this.state = TEBGameStatus.GS_WK_SHAKE_DICE;
//         if (AppData.getInstance().isGameHide) {
//             this.callUI("setDiceResultByData", data, this.getNoByChair(data.wFirstGetCardUser));
//         } else {
//             this.callUI("setDiceResult", data, this.getNoByChair(data.wFirstGetCardUser));
//         }
//         for (var i = 0; i < 4; i++) {
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//     }
//     //用户退出
//     public playerExit(data: any) {
//         this.callData("setPlayerExit");
//     }
//     //开牌结果
//     public openCard(data: any) {
//         this.state = TEBGameStatus.GS_WK_OPEN_CARD;
//         this.callData("setGameResult", data);
//         //停止上一操作
//         this.callUI("stopDiceAnimation");
//         this.checkOpenCard();
//         this.callData("setEndFlag", data.bGameEndFlg);
//         for (var i = 0; i < 4; i++) {
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//     }
//     //按下返回按钮
//     public onBackButton(): void {
//         this.communicate(LoaddingGlobalModule.response.showLoad);
//         this.isBackstatus = BackStatusConfig.back;
//         this.clickQuitFlag = true;
//         this.hallSocket.send(CMDConfig.SEND_LEAVE_GAME, {});
//         this.hallSocket.send(CMDConfig.SEND_LEAVE_ROOM, {});
//     }
//     //按下取消匹配按钮
//     public onCancelButton(): void {
//         this.hallSocket.send(CMDConfig.SEND_STANDUP, {});
//         this.isBackstatus = BackStatusConfig.quXiaoPiPei;
//         this.quxiaopipeiSuccess = false;
//         this.callUI("hidePiPeiUI");
//     }
//     public gameEnd() {
//     }
//     /********************************************************************** */
//     //设置输赢结果
//     private setPrizeResult(list: Array<number>, cardData: Array<number>, playerScore: Array<number>) {
//         var info = [], chairId = this.chairId, banker = this.callData("getBanker");
//         var cellScore = AppData.getInstance().currentRoom.cellScore;
//         for (var i = 0; i < 4; i++) {
//             var player = this.getPlayerByChair(i), score = list[i];
//             //设置界面
//             this[player].setPrizeAnimation(score, playerScore[i]);
//             if (score > 0 && i != banker) {
//                 info.push({
//                     player: this.getNoByChair(i),
//                     value: this.callData("getChipList", score)
//                 });
//             }
//         }
//         this.callUI("setOpenCardData", cardData);
//         if (AppData.getInstance().isGameHide) {
//             this.callUI("removeAllChip", this.getNoByChair(banker), info);//赢家筹码 
//         } else {
//             this.callUI("setResultChip", this.getNoByChair(banker), info);//赢家筹码 
//         }
//     }
//     //检查是否可以进行开牌
//     private checkOpenCard() {
//         if (this.callData("checkOpenCard")) {
//             var data = this.callData("getGameResult");//获取开牌信息
//             var player = data.wFirstGetCardUser, cbHandCardData = data.cbHandCardData, time = 1000, list = data.cbPrizeCount,
//                 cellScore = AppData.getInstance().currentRoom.cellScore, resultList: Array<TEBResultData> = [];
//             //计算庄家倍数
//             var wAddScoreTimes = data.wAddScoreTimes, bankerTime = 0;
//             for (var t = 0; t < 4; t++) {
//                 if (list[t] > 0) {
//                     bankerTime -= wAddScoreTimes[t];
//                 } else {
//                     bankerTime += wAddScoreTimes[t];
//                 }
//             }
//             wAddScoreTimes[data.wBankerUser] = Math.abs(bankerTime);
//             for (var p = 0; p < 4; p++) {
//                 this["player" + p].sendCard();
//             }
//             var exTime = 0;//增加动画时间
//             for (var i = 0; i < 4; i++) {
//                 var cardData = cbHandCardData[player];
//                 var type = this.callData("getCardType", cardData);
//                 if (type > 20) {
//                     exTime += 400;
//                 }
//                 this[this.getPlayerByChair(player)].setOpenCard(time * i + exTime, cardData, this.callData("getCardType", cardData));
//                 player = player == 3 ? 0 : ++player;

//                 var item: TEBResultData = new TEBResultData(), playerCount = this.getPlayerByChair(i), score = list[i];
//                 item.nickname = this[playerCount].data.nickName;
//                 item.base = cellScore;
//                 item.score = score;
//                 item.times = wAddScoreTimes[i];
//                 resultList.push(item);
//             }
//             this.callData("setResultData", resultList);
//             if (AppData.getInstance().isGameHide) {
//                 this.setPrizeResult(data.cbPrizeCount, data.cbOpenCardData, data.llPlayerScore);
//             } else {
//                 //检查通杀或者通赔
//                 var allKill = true, allWin = true;
//                 if (data.cbPrizeCount[this.bankerChair] > 0) {
//                     for (var k = 0; k < 4; k++) {
//                         if (k != this.bankerChair && data.cbPrizeCount[k] > 0) {
//                             allKill = false;
//                         }
//                     }
//                     allWin = false;
//                 } else {
//                     for (var k = 0; k < 4; k++) {
//                         if (k != this.bankerChair && data.cbPrizeCount[k] < 0) {
//                             allWin = false;
//                         }
//                     }
//                     allKill = false;
//                 }
//                 // allKill = true;
//                 egret.setTimeout(function () {
//                     if (allKill) {
//                         this.callUI("allKillAnimation");
//                     } else if (allWin) {
//                         this.callUI("allWinAnimation");
//                     }
//                 }, this, 4000 + exTime);

//                 if (allKill || allWin) {
//                     exTime += 1000;
//                 }
//                 egret.setTimeout(this.setPrizeResult, this, 4000 + exTime, data.cbPrizeCount, data.cbOpenCardData, data.llPlayerScore);
//             }
//         }
//     }
//     //设置庄家
//     private startRandomBanker() {
//         this.totalTime = 8 + this.bankerChair;
//         if (this.bankerInterval != -1) {
//             egret.clearInterval(this.bankerInterval);
//             this.bankerInterval = -1;
//         }
//         this.bankerInterval = egret.setInterval(this.runRandomBanker, this, 200);
//     }
//     private runRandomBanker() {
//         this.runningTime++;
//         if (!AppData.getInstance().isGameHide) {
//             this[this.getPlayerByChair(this.bankerList[(this.runningTime % this.bankerLenght)])].startRandomBanker();
//         }
//         if (this.totalTime <= this.runningTime) {
//             egret.clearInterval(this.bankerInterval);
//             this.bankerInterval = -1;
//             this.setBankerByIndex(this.bankerChair);
//         }
//     }
//     private setBankerByIndex(index: number) {
//         if (this.bankerInterval != -1) {
//             egret.clearInterval(this.bankerInterval);
//             this.bankerInterval = -1;
//         }
//         for (var i = 0; i < 4; i++) {
//             this["player" + i].stopBankerAnimation();
//         }
//         this[this.getPlayerByChair(index)].setBankerAnimation();
//         this.callUI("resetBetInfo");
//     }
//     //删除结果界面
//     public resultRemove(value: boolean) {
//         this.resultFlag = false;
//         //玩家离开游戏或者继续按钮，需要重新匹配
//         // var endFlag = this.callData("getLastGame"), round = this.callData("getRound");
//         var endFlag = this.callData("getLastGame");
//         this.callUI("setPlayingFlag", endFlag);
//         if (endFlag == 2) {
//             //余额不足，退出房间
//             AppData.getInstance().gameData.gameStart = false;
//             this.state = TEBGameStatus.GS_WK_GAME_OVER;
//             this.onBackButton();
//             how.Alert.show(TEBLanguage.noMoney);
//         } else if (value) {
//             this.restartGame();
//             this.callUI("setContinueGroup", false);
//         } else if (endFlag == 1) {//五局之后获取游戏结束，提示继续游戏
//             this.callUI("resetGame");
//             this.callUI("setContinueGroup", true);
//             AppData.getInstance().gameData.gameStart = false;
//             this.state = TEBGameStatus.GS_WK_GAME_OVER;
//         } else {
//             for (var i = 0; i < 4; i++) {
//                 this["player" + i].restart();
//             }
//             this.callUI("setContinueGroup", false);
//             this.callUI("stopGameStartCountDown");
//             //当前状态为开始游戏状态
//             if (this.state == TEBGameStatus.GS_WK_READY) {
//                 this.callUI("startAnimationByTime", 200);
//             }
//         }
//     }
//     /********************************report******************************** */
//     private introduction() {
//         this.moduleManager.initModule(TEBHelpWindowModule, TEBHelpWindowView, TEBHelpWindowData);
//     }
//     private record() {
//         this.moduleManager.initModule(TEBGameRecordModule, TEBGameRecordView);
//         var windowList = how.WindowManager.getInstance().windowList, len = windowList.length;
//         for (var i = 0; i < len; i++) {
//             if (windowList[i] instanceof how.Alert) {
//                 how.WindowManager.getInstance().closeWindow(windowList[i]);
//             }
//         }
//     }
//     private setting() {
//         how.SettingWindow.show();
//     }
//     private noGrab() {
//         if (this.clickedFlag) return;
//         this.clickedFlag = true;
//         this.hallSocket.send(TEBCMDConfig.TEB_SEND_CALL_BANKER, { bBanker: 0, wBankerTime: 0 });
//         this["player0"].setGrabBanker(this.callData("getGameType"), 0);
//     }
//     private grab(times: number) {
//         if (this.clickedFlag) return;
//         this.clickedFlag = true;
//         this.hallSocket.send(TEBCMDConfig.TEB_SEND_CALL_BANKER, { bBanker: 1, wBankerTime: times });
//         this["player0"].setGrabBanker(this.callData("getGameType"), times);
//     }
//     private continue() {
//         this.restartGame();
//         this.resultFlag = false;
//     }
//     private displayBanker() {
//         var index = this.callData("getBanker");
//         for (var i = 0; i < 4; i++) {
//             if (i == index) {
//                 this[this.getPlayerByChair(i)].setBanker(true);
//             } else {
//                 this[this.getPlayerByChair(i)].setBanker(false);
//             }
//         }
//     }
//     private chipLeave() {
//         this.callUI("removeAllAnimation");
//         //最后一局，移除玩家
//         var value: number = this.callData("getLastGame");
//         if (value == 1 || value == 2) {
//             this.callData("rsetPlayerListByData", [base.Utils.getItem(this.data["playerList"], "id", AppData.getInstance().userData.id)]);
//             this["player0"].restart(0);
//             //游戏结束界面
//             if (!this.resultFlag) {
//                 this.moduleManager.initModule(TEBResultWindowModule, TEBResultWindowView, TEBResultWindowData);
//                 this.resultFlag = true;
//             }
//             var resultList: Array<TEBResultData> = this.callData("getResultData");
//             //获取不到数据
//             if (resultList.length == 0) {
//                 var data = this.callData("getGameResult");//获取开牌信息
//                 if (data == null) return;
//                 var list = data.cbPrizeCount, cellScore = AppData.getInstance().currentRoom.cellScore;
//                 //计算庄家倍数
//                 var wAddScoreTimes = data.wAddScoreTimes, bankerTime = 0;
//                 for (var t = 0; t < 4; t++) {
//                     if (list[t] > 0) {
//                         bankerTime -= wAddScoreTimes[t];
//                     } else {
//                         bankerTime += wAddScoreTimes[t];
//                     }
//                 }
//                 wAddScoreTimes[data.wBankerUser] = Math.abs(bankerTime);
//                 for (var i = 0; i < 4; i++) {
//                     var item: TEBResultData = new TEBResultData();
//                     item.nickname = this[this.getPlayerByChair(i)].data.nickName;
//                     item.base = cellScore;
//                     item.score = list[i];
//                     item.times = wAddScoreTimes[i];
//                     resultList.push(item);
//                 }
//             }
//             this.noShowEver = true;
//             this.communicate(TEBResultWindowModule.response.setInfo, resultList, this.chairId, this.callData("getBanker"),
//                 this.callData("getLastGame"), this.callData("getRound"));
//             for (var i = 1; i < 4; i++) {
//                 this["player" + i].data = null;
//             }
//             this.callData("clearPlayerList");
//         }
//     }
//     //开牌
//     private playerCard(index: number) {
//         this["player" + index].sendCard();
//     }
//     //开始翻牌标志
//     private setOpenCardFlag() {
//         this.callData("setOpenCardFlag", true);
//         this.checkOpenCard();
//     }
//     //下注信息
//     private callScore(time: number) {
//         if (this.clickedFlag) return;
//         this.clickedFlag = true;
//         this.hallSocket.send(TEBCMDConfig.TEB_SEND_CALL_SCORE, { wScoreTime: time });
//     }
//     private setFirstAnimation(index: number) {
//         this["player" + index].setFirstAnimation();
//     }
//     /********************************************************************** */
//     public restartGame() {
//         this.callUI("resetGame");
//         if (AppData.getInstance().userData.status == UserStatus.PLAY) {
//             this.hallSocket.send(CMDConfig.SEND_STANDUP, {});
//             this.isBackstatus = BackStatusConfig.resumeGame;
//         } else {
//             this.isBackstatus = BackStatusConfig.pipei;
//             this.callUI("resetRecordCard");
//             //坐下
//             this.state = TEBGameStatus.GS_WK_NULL;
//             this.chairId = -1;
//             this.hallSocket.send(CMDConfig.SEND_SIT, {
//                 wTableID: 0,
//                 wChairID: 65535,
//                 szTablePass: AppData.getInstance().currentRoom.szTablePass,
//                 cbPassLen: AppData.getInstance().currentRoom.cbPassLen,
//                 CellScore: AppData.getInstance().currentRoom.cellScore,
//                 PreScore: AppData.getInstance().currentRoom.preScore
//             });
//             this.callUI("setContinueGroup", false);
//         }
//     }
//     //坐下失败
//     private sitError(data: any): void {
//         how.Banner.show(LanguageConfig["error_" + data.wOperatorValue]);
//         this.callUI("hidePiPeiUI");//隐藏匹配界面
//         this.callUI("setContinueGroup", true);
//     }
//     //获取座位玩家
//     private getPlayerByChair(chairID: number) {
//         return "player" + (chairID + 4 - D.App.userData.chairID/*this.chairId*/) % 4;
//     }
//     private getNoByChair(chairID: number) {
//         return (chairID + 4 - D.App.userData.chairID/*this.chairId*/) % 4;
//     }
//     /*******************************断线重连******************************* */
//     public onReConnected(data: any): void {
//         if (this.state == TEBGameStatus.GS_WK_GAME_OVER) {
//             return;
//         }
//         this.chairId = D.App.userData.chairID/*AppData.getInstance().userData.chairID*/;
//         this.callData("checkPlayerList");//玩家确定桌子号之后，查找同桌子ID的玩家
//         this.callUI("reConnectGame");
//         this.callData("setGameType", data.wGameType);
//         this.callData("setRound", data.cbRetsOfRound);
//         this.callData("setBaseScore", AppData.getInstance().currentRoom.cellScore);
//         AppData.getInstance().gameData.gameStart = true;
//         switch (data.cbStatus) {
//             case TEBGameStatus.GS_WK_READY://准备状态
//                 this.reConnectReady(data);
//                 break;
//             case TEBGameStatus.GS_WK_CALL_BANKER://抢庄状态
//                 this.reConnectCallBanker(data);
//                 break;
//             case TEBGameStatus.GS_WK_SET_BANKER://庄家宣布状态
//                 this.reConnectSetBanker(data);
//                 break;
//             case TEBGameStatus.GS_WK_CALL_BET://投注状态
//                 this.reConnectBet(data);
//                 break;
//             case TEBGameStatus.GS_WK_SHAKE_DICE://骰子状态
//                 this.reConnectShakeDice(data);
//                 break;
//             case TEBGameStatus.GS_WK_OPEN_CARD://开奖状态
//                 this.reConnectOpenCard(data);
//                 break;
//             default:
//                 break;
//         }
//     }
//     //准备阶段
//     public reConnectReady(data: any): void {
//         this.callUI("reConnectReady", data);
//         for (var i = 0, score: Array<number> = data.playerScore, len = score.length; i < len; i++) {
//             this[this.getPlayerByChair(i)].setPlayerScore(score[i]);//玩家分数
//         }
//     }
//     //抢庄状态
//     // {"wGameType":2,"dwGameStartTime":1497782625,"cbStatus":102,"cbBankerStatus":[2,2,0,2],"wCallBankerTimes":[0,0,0,0],"lCellScore":100,
//     // "cbRetsOfRound":1,"cbOpenCardData":[0,0,0,0,0,0,0,0,0,0],"playerScore":[31495,40810,24480,40235],"wMaxTime":100,"cbCountDown":4} 
//     public reConnectCallBanker(data: any): void {
//         this.callUI("reConnectCallBanker", data);
//         for (var i = 0, score: Array<number> = data.playerScore, len = score.length; i < len; i++) {
//             var player = this[this.getPlayerByChair(i)];
//             player.setPlayerScore(score[i]);//玩家分数
//             switch (data.cbBankerStatus[i]) {
//                 case 0:
//                     if (i == this.chairId) {
//                         //我方没抢庄
//                         var cbCountDown = 4 - data.cbCountDown;
//                         if (cbCountDown < 0) {
//                             cbCountDown = 0;
//                         }
//                         this.callUI("startBanker", data, cbCountDown);
//                     } else {
//                         player.setThinking();
//                     }
//                     break;
//                 case 1://抢庄
//                     player.setGrabBanker(data.wGameType, data.wCallBankerTimes[i]);
//                     this.callData("updataBanker", i);
//                     break;
//                 case 2://不抢庄
//                     player.setGrabBanker(data.wGameType, data.wCallBankerTimes[i]);
//                     break;
//             }
//         }
//     }
//     //庄家状态
//     // {"wGameType":2,"dwGameStartTime":1497778277,"cbStatus":103,"wBankerUser":0,"lCellScore":100,"cbRetsOfRound":1,
//     // "cbOpenCardData":[0,0,0,0,0,0,0,0,0,0],"playerScore":[40955,0,0,0]} 
//     public reConnectSetBanker(data: any) {
//         this.callUI("reConnectReady", data);
//         this.callData("setBanker", data.wBankerUser);
//         this.setBankerByData(data.wBankerUser);
//         for (var i = 0, score: Array<number> = data.playerScore, len = score.length; i < len; i++) {
//             this[this.getPlayerByChair(i)].setPlayerScore(score[i]);//玩家分数
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//     }
//     //投注状态
//     // {"wGameType":2,"dwGameStartTime":1497773772,"cbStatus":104,"wBankerUser":0,"lCellScore":100,"cbRetsOfRound":1,
//     // "cbOpenCardData":[0,0,0,0,0,0,0,0,0,0],"lplayerScore":[40310,0,0,0],"lAddScore":[0,100,0,100],"cbCountDown":4}
//     public reConnectBet(data: any) {
//         this.callUI("setBankerFlag", this.chairId == wBankerUser);
//         this.callUI("reConnectBet", data);
//         var baseScore = AppData.getInstance().currentRoom.cellScore, gemeType = data.wGameType, myFlag = true, lAddScore = data.lAddScore;
//         var wBankerUser = data.wBankerUser;
//         this.setBankerByData(wBankerUser);
//         var totalBetScore = 0, myBetScore = 0;
//         for (var i = 0, score: Array<number> = data.lplayerScore, len = score.length; i < len; i++) {
//             var addScore = lAddScore[i];
//             if (addScore > 0) {
//                 var temp = {
//                     wGameType: gemeType,
//                     lAddScoreCount: addScore,
//                     lplayerScore: score[i],
//                     lAddScoreTimes: addScore / baseScore,//计算倍数
//                 }
//                 this[this.getPlayerByChair(i)].setBetScore(temp);
//                 this.callUI("setChipByData", this.callData("getChipList", addScore));
//             } else {
//                 if (i != this.chairId && i != wBankerUser) {
//                     this[this.getPlayerByChair(i)].setThinking();
//                 }
//             }
//             totalBetScore += addScore;
//             if (i == this.chairId) {
//                 myBetScore = addScore;
//                 if (addScore > 0) {
//                     myFlag = false;//我已经投注
//                 }
//             }
//             this[this.getPlayerByChair(i)].setPlayerScore(score[i]);//玩家分数
//         }
//         if (myFlag && this.chairId != wBankerUser) {
//             if (data.wGameType == 1) {//普通房直接返回
//                 this.callScore(1);
//             } else {
//                 this.callUI("startCallScore", data, 6 - data.cbCountDown);
//             }
//         } else {
//             this.callUI("startCallScore1", 6 - data.cbCountDown);
//         }
//         this.callUI("setBankerInfoByData", totalBetScore, myBetScore);
//     }
//     //骰子状态
//     // {"wGameType":2,"dwGameStartTime":11051,"cbStatus":105,"cbBanker":2,"lCellScore":100,"cbRetsOfRound":1,"cbOpenCardData":[1,1,2,0,0,0,1,0,1,2],
//     // "playerScore":[41525,32695,23235,40840],"cbDice1":5,"cbDice2":3,"wFirstGetCardUser":1,"lAddScore":[0,0,0,0]} 
//     public reConnectShakeDice(data: any): void {
//         this.callUI("reConnectShakeDice", data);
//         this.callUI("setBankerFlag", this.chairId == data.cbBanker);
//         this.setBankerByData(data.cbBanker);
//         this.setFirstAnimation(data.wFirstGetCardUser);
//         var baseScore = AppData.getInstance().currentRoom.cellScore, gemeType = data.wGameType, addScore = data.lAddScore;
//         var totalBetScore = 0, myBetScore = 0;
//         for (var i = 0, score: Array<number> = data.playerScore, len = score.length; i < len; i++) {
//             var addingScore = addScore[i];
//             if (addingScore > 0) {
//                 var temp = {
//                     wGameType: gemeType,
//                     lAddScoreCount: addingScore,
//                     lplayerScore: score[i],
//                     lAddScoreTimes: addingScore / baseScore,//计算倍数
//                 }
//                 this[this.getPlayerByChair(i)].setBetScore(temp);
//                 this.callUI("setChipByData", this.callData("getChipList", addingScore));
//                 totalBetScore += addingScore;
//                 if (i == this.chairId) {
//                     myBetScore = addingScore;
//                 }
//             }
//             this[this.getPlayerByChair(i)].setPlayerScore(score[i]);//玩家分数
//             this[this.getPlayerByChair(i)].unsendCard();
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//         this.callUI("setBankerInfoByData", totalBetScore, myBetScore);
//     }
//     //开奖状态
//     //{"wGameType":2,"dwGameStartTime":1498037777,"cbStatus":106,"lCellScore":100,"cbRetsOfRound":2,"cbOpenCardData":[2,2,1,2,1,2,1,1,3,1],
//     // "lAddScore":[100,0,100,700],"playerScore":[571,3011,225885,100470],"cbBanker":1,"cbHandCardData":[[6,8],[3,4],[2,5],[9,7]],
//     // "cbPrizeCount":[-100,665,95,-700],"bGameEndFlg":0} 
//     public reConnectOpenCard(data: any): void {
//         if (!AppData.getInstance().gameData.gameStart) { }
//         this.callUI("reConnectOpenCard", data);
//         var cellScore = data.lCellScore;
//         this.setBankerByData(data.cbBanker);

//         var cbHandCardData = data.cbHandCardData, cbPrizeCount = data.cbPrizeCount, resultList: Array<TEBResultData> = [],
//             score: Array<number> = data.playerScore, len = score.length;
//         //计算庄家倍数
//         var lAddScore = data.lAddScore, bankerTime = 0;
//         for (var t = 0; t < 4; t++) {
//             if (score[t] > 0) {
//                 bankerTime -= lAddScore[t];
//             } else {
//                 bankerTime += lAddScore[t];
//             }
//         }
//         lAddScore[data.cbBanker] = Math.abs(bankerTime);
//         var totalBetScore = 0, myBetScore = 0;
//         for (var i = 0; i < len; i++) {
//             //玩家界面设置
//             var player = this[this.getPlayerByChair(i)], cardData = cbHandCardData[i], prize = cbPrizeCount[i];
//             player.setPlayerScore(score[i]);//玩家分数
//             player.setCardResult(cardData, this.callData("getCardType", cardData), prize);
//             //保存开奖结果界面信息
//             var item: TEBResultData = new TEBResultData();
//             item.nickname = player.data.nickName;
//             item.base = cellScore;
//             item.score = prize;
//             item.times = lAddScore[i] / cellScore;
//             resultList.push(item);
//             //计算投注信息
//             var addingScore = data.lAddScore[i];
//             totalBetScore += addingScore;
//             if (i == this.chairId) {
//                 myBetScore = addingScore;
//             }
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//         this.callData("setResultData", resultList);
//         this.callData("setEndFlag", data.bGameEndFlg);
//         //3秒之后，出现结束界面
//         if (this.resultTimeout != -1) {
//             egret.clearTimeout(this.resultTimeout);
//             this.resultTimeout = -1;
//         }
//         this.resultTimeout = egret.setTimeout(this.chipLeave, this, 3000);
//         this.callUI("setBankerInfoByData", totalBetScore, myBetScore);
//     }
//     /**设置庄家 */
//     private setBankerByData(index: number) {
//         for (var i = 0; i < 4; i++) {
//             if (i == index) {
//                 this[this.getPlayerByChair(i)].setBanker(true);
//             } else {
//                 this[this.getPlayerByChair(i)].setBanker(false);
//             }
//         }
//         this.bankerChair = index;
//         this.callData("setBanker", index);
//     }
//     /*******************************适配******************************** */
//     private onResize() {
//         this.callUI("resizeUI");
//     }
//     /*******************************后台切换**************************** */
//     private appHide() {
//         this.callUI("appHide", this.state);
//         if (!AppData.getInstance().gameData.gameStart) {
//             return;
//         }
//         //关闭结果页面
//         if (this.resultFlag) {
//             this.communicate(TEBResultWindowModule.response.closeResult);
//             this.resultFlag = false;
//         }
//         if (this.state == TEBGameStatus.GS_WK_OPEN_CARD) {
//             if (this.callData("checkOpenCard")) {
//                 var data = this.callData("getGameResult");//获取开牌信息
//                 var info = [], chairId = this.chairId, banker = this.callData("getBanker");
//                 for (var i = 0; i < 4; i++) {
//                     var player = this[this.getPlayerByChair(i)], cardData = data.cbHandCardData[i], prize = data.cbPrizeCount[i];
//                     player.setCardResult(cardData, this.callData("getCardType", cardData), prize);
//                     player.setPrizeAnimation(prize, data.llPlayerScore[i]);
//                     if (prize > 0 && i != banker) {
//                         info.push({
//                             player: this.getNoByChair(i),
//                             value: this.callData("getChipList", prize)
//                         });
//                     }
//                 }
//                 this.callUI("removeAllChip", this.getNoByChair(banker), info);//赢家筹码 
//             }
//         }
//         for (var i = 0; i < 4; i++) {
//             this[this.getPlayerByChair(i)].closeThinking();
//         }
//     }
//     private appResume() {
//         AppData.getInstance().isGameHide = false;
//         if (this.noShowEver) {
//             return;
//         }
//         for (var i = 0; i < 4; i++) {
//             this["player" + i].resume();
//         }
//         if (this.bankerInterval != -1) {
//             egret.clearInterval(this.bankerInterval);
//             this.bankerInterval = -1;
//             this.setBankerByIndex(this.bankerChair);
//         }
//         //检查是不是为最后一局，而且没有打开结束界面
//         if (!this.resultFlag) {
//             this.chipLeave();
//         }
//         if (!AppData.getInstance().gameData.gameStart) {
//             this.noShowEver = true;
//             return;
//         }
//         this.callUI("appResume");
//     }
//     /*******************************退出******************************* */
//     public onBack(): void {
//         this.callUI("quitTap");
//     }
//     public onDestroy(): void {
//         super.onDestroy();
//     }

//     public onSystemTalk(data: any): void {
//         switch (data.wMessageType) {
//             case 2000://关闭房间
//                 //退出房间时，同步数据中
//                 if (data.szContent == 87 && this.clickQuitFlag) {
//                     //除去loading页
//                     this.communicate(LoaddingGlobalModule.response.hideLoad);
//                     how.Alert.show(LanguageConfig["hall_error_" + data.szContent]);
//                     this.clickQuitFlag = false;
//                 }
//                 break;
//         }
//     }
// }
